﻿using System;

namespace LxCFD
{
    public class FvContactBase : HeadBase, IProvideContactTopology, IPrepareMesh
    {
        public bool IsEnabled { get; set; }
        public bool IsConode { get; set; }
        public IndexNumber InnerIndex { get; set; }
        public FvPair[] Pairs;
        public FvCell[] OCells;
        public FvCell[] NCells;
        public AMGInContact AMGSolver { get; set; }
        public BiCGStabInZone O_BiCGSolver;
        public BiCGStabInZone N_BiCGSolver;
        //not local
        public FvZone OZone;
        public FvThread OThread;
        public FvZone NZone;
        public FvThread NThread;
        public void PrepareMeshData()
        {
            OCells = OZone.Cells;
            NCells = NZone.Cells;
            if (IsConode)
            {
                LxTool.CheckCreateArray(ref Pairs, OThread.ThreadIndex.FaceIDs.GetCount());
                int deltaOFaceId = OThread.ThreadIndex.FaceIDs.Start;
                int deltaNFaceId = NThread.ThreadIndex.FaceIDs.Start;
                int deltaOCellId = OThread.ThreadIndex.CellIDs.Start;
                int deltaNCellId = NThread.ThreadIndex.CellIDs.Start;
                for (int i1 = 0; i1 < Pairs.Length; i1++)
                {
                    Pairs[i1].SetONIndex(i1 + deltaOFaceId, ref OZone.Faces[i1 + deltaOFaceId], i1 + deltaNFaceId, ref NZone.Faces[i1 + deltaNFaceId]);
                    OCells[i1 + deltaOCellId].OFaces = new int[] { i1 };
                    NCells[i1 + deltaNCellId].OFaces = new int[] { i1 };
                }
                InnerIndex = new IndexNumber(0, Pairs.Length - 1, 0, Pairs.Length - 1);
            }
            else
            {
                LxConsole.Error("暂不支持非共节点界面");
            }
        }
        public int[] GetOZoneCellOFaces(int cellID)
        {
            return OCells[cellID].OFaces;
        }

        public int[] GetNZoneCellOFaces(int cellID)
        {
            return NCells[cellID].OFaces;
        }

        public IndexNumber GetInnerIndex()
        {
            return InnerIndex;
        }
    }
}

//IndexNumber IProvideContactTopology.getOwnerIndex()
//{
//    return ownerThread.ThreadIndex;
//}

//IndexNumber IProvideContactTopology.getNeighborIndex()
//{
//    return neighborThread.ThreadIndex;
//}
